package com.bsdsma.visonManagementSystemapp.dto;

import com.bsdsma.visonManagementSystemapp.entity.Student;
import com.bsdsma.visonManagementSystemapp.entity.Teacher;
import com.bsdsma.visonManagementSystemapp.entity.Admin;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;

/**
 * DTO for representing any type of user (Student, Teacher, Admin)
 */
@Data
public class UserDto {
    private Long id;
    private String account;
    private String password;
    private String headImgKey;
    private String name;
    private String cellphoneNumber;
    private String role;
    private String xuexiao;
    private String nianji;
    private Integer banji;
    private Long xuehao;
    private Long gonghao;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date ct;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date ut;

    private Integer status;

    /**
     * Convert a Student to UserDto
     */
    public static UserDto fromStudent(Student student) {
        if (student == null) return null;
        UserDto dto = new UserDto();
        dto.setId(student.getId());
        dto.setAccount(student.getAccount());
        dto.setPassword(student.getPassword());
        dto.setHeadImgKey(student.getHeadImgKey());
        dto.setName(student.getName());
        dto.setCellphoneNumber(student.getCellphoneNumber());
        dto.setRole(student.getRole());
        dto.setXuexiao(student.getXuexiao().getName());
        dto.setNianji(student.getNianji() != null ? student.getNianji().getDisplayName() : null);
        dto.setBanji(student.getBanji());
        dto.setXuehao(student.getXuehao());
        dto.setCt(student.getCt());
        dto.setUt(student.getUt());
        dto.setStatus(student.getStatus());
        return dto;
    }

    /**
     * Convert a Teacher to UserDto
     */
    public static UserDto fromTeacher(Teacher teacher) {
        if (teacher == null) return null;
        UserDto dto = new UserDto();
        dto.setId(teacher.getId());
        dto.setAccount(teacher.getAccount());
        dto.setPassword(teacher.getPassword());
        dto.setHeadImgKey(teacher.getHeadImgKey());
        dto.setName(teacher.getName());
        dto.setCellphoneNumber(teacher.getCellphoneNumber());
        dto.setRole(teacher.getRole());
        dto.setXuexiao(teacher.getXuexiao().getName());
        dto.setGonghao(teacher.getGonghao());
        dto.setCt(teacher.getCt());
        dto.setUt(teacher.getUt());
        dto.setStatus(teacher.getStatus());
        return dto;
    }

    /**
     * Convert an Admin to UserDto
     */
    public static UserDto fromAdmin(Admin admin) {
        if (admin == null) return null;
        UserDto dto = new UserDto();
        dto.setId(admin.getId());
        dto.setAccount(admin.getAccount());
        dto.setPassword(admin.getPassword());
        dto.setHeadImgKey(admin.getHeadImgKey());
        dto.setName(admin.getName());
        dto.setCellphoneNumber(admin.getCellphoneNumber());
        dto.setRole(admin.getRole());
        dto.setGonghao(admin.getGonghao());
        dto.setCt(admin.getCt());
        dto.setUt(admin.getUt());
        dto.setStatus(admin.getStatus());
        return dto;
    }
} 